# Maintainer: Marko Käning <mk-lists@mailbox.org>

_realname=bsdfprocessor
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.3.0
pkgrel=1
epoch=
pkgdesc="Application for displaying and editing of BSDF files (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/KimuraRyo/BSDFProcessor'
license=('spdx:MPL-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-OpenSceneGraph"
         "${MINGW_PACKAGE_PREFIX}-osgQt"
         "${MINGW_PACKAGE_PREFIX}-omp")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-eigen3"
             "${MINGW_PACKAGE_PREFIX}-libbsdf")
source=("https://github.com/KimuraRyo/${_realname}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        '001-compiler-flags.patch')
sha256sums=('2b1e7e5eed38f2ac3f71112c7d2476a9175395dd1df5b3e7996c8ab88e68e9c5'
            '1a449c5a2c0ef00044867002c7e8c0d0fff0928712210931e93e3c83ffb70462')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/001-compiler-flags.patch"
}

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"Ninja" \
    -DCMAKE_BUILD_TYPE=Release \
    -DEIGEN3_INCLUDE_DIR=${MINGW_PREFIX}/include/eigen3 \
    -DLIBBSDF_DIR=${MINGW_PREFIX}/include/libbsdf \
    -DCMAKE_CXX_STANDARD=11 \
    ../${_realname}-${pkgver}

  cmake --build .
}

package() {
  mkdir -p "${pkgdir}"${MINGW_PREFIX}/bin
  cp -f "${srcdir}"/build-${MSYSTEM}/BSDFProcessor.exe "${pkgdir}"${MINGW_PREFIX}/bin/bsdfprocessor.exe

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}
  cp -f "${srcdir}"/${_realname}-${pkgver}/LICENSE "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}
}
